/**
 * 将 Map 或对象拼接为查询参数
 * @param params Map 或对象
 * @returns 拼接后的查询字符串
 */
export function toQueryString(params: Record<string, any> | Map<string, any>): string {
    const queryArray: string[] = [];

    if (params instanceof Map) {
        params.forEach((value, key) => {
            queryArray.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
        });
    } else {
        Object.entries(params).forEach(([key, value]) => {
            queryArray.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
        });
    }

    return queryArray.join('&');
}